package com.xxl.job.executor.crawler.util;

import com.xxlComments.job.executor.crawler.util.ElementUtil;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.util.ArrayList;
import java.util.List;

/**
 * 描述:
 * 解析itemid 和 sku
 *
 * @author Pfly
 * @create 2019-01-07 15:46
 */
public class SkuAndItemIdUtil {


    public static List<String> getItemId(List<String> css){
        //用以存储 传过来的pageVo
        List<String> all = new ArrayList<>();
        //遍历解析出所有包含Item id 的span标签
        for (String s : css) {
            if(s.contains("Item ID")){
                all.add(s);
            }
        }

        //将每个遍历出来的数据追加到stringBuffer中
        StringBuffer sb = new StringBuffer();
        for (String data : all){
            sb.append(data);
        }
        // 将stringBuffer转换成string
        String spanAll = sb+"";

        //用jsoup 解析标签 ，返回itemid的list
        Document parse = Jsoup.parse(spanAll);
        Element body = parse.body();
        Elements select = body.select(".value");
        List<String> itemId = ElementUtil.ergodicByHtml(select);
        return itemId;
    }



    public static List<String> getSku(List<String> css){
        //用以存储 传过来的pageVo
        List<String> all = new ArrayList<>();
        //遍历解析出所有包含Sku 的span标签
        for (String s : css) {
            if(s.contains("SKU :")){
                all.add(s);
            }
        }

        //将每个遍历出来的数据追加到stringBuffer中
        StringBuffer sb = new StringBuffer();
        for (String data : all){
            sb.append(data);
        }
        // 将stringBuffer转换成string
        String spanAll = sb+"";

        //用jsoup 解析标签 ，返回itemid的list
        Document parse = Jsoup.parse(spanAll);
        Element body = parse.body();
        Elements select = body.select(".value");
        List<String> sku = ElementUtil.ergodicByHtml(select);
        return sku;
    }
}
